import request from '@/utils/request'

export function getMenusTree(pid) {
  return request({
    url: 'api/menu/childNodes/' + pid,
    method: 'post',
    loading: true
  })
}

export function getChild(id) {
  return request({
    url: '/api/menu/childMenus/' + id,
    method: 'post'
  })
}

export function buildMenus() {
  return request({
    url: 'api/dynamicMenu/menus',
    method: 'post'
  })
}

export function addMenu(data) {
  return request({
    url: '/api/menu/create',
    method: 'post',
    data
  })
}

export function delMenu(ids) {
  return request({
    url: '/api/menu/delete',
    method: 'post',
    data: ids
  })
}

export function editMenu(data) {
  return request({
    url: '/api/menu/update',
    method: 'post',
    data
  })
}

export function treeByMenuId(menuId) {
  return request({
    url: '/api/menu/nodesByMenuId/' + menuId,
    method: 'post'
  })
}

export function queryCondition(data) {
  return request({
    url: '/api/menu/search',
    method: 'post',
    data
  })
}




// 新加菜单




//查询所有菜单
export function querySysMenu(data) {
  return request({
    url: '/api/menu/querySysMenu',
    method: 'post',
    data
  })
}

//查询某一个菜单关联的角色数据
export function queryMenusAndRoleByMenuId(data) {
  return request({
    url: `/api/menu/queryMenusAndRoleByMenuId?menuId=${data}`,
    method: 'post',
    data
  })
}

//查询某一个菜单数据
export function queryById(data) {
  return request({
    url: `/api/menu/queryById?menuId=${data}`,
    method: 'post',
    data
  })
}

//新增、修改菜单数据
export function insertMenu(data) {
  return request({
    url: '/api/menu/insertMenu',
    method: 'post',
    data
  })
}

//删除某一个菜单数据
export function deleteById(data) {
  return request({
    url: `/api/menu/deleteById?menuId=${data}`,
    method: 'post',
    data
  })
}

//指定菜单关联角色数据
export function associationMenuAndRole(data) {
  return request({
    url: '/api/menu/associationMenuAndRole',
    method: 'post',
    data
  })
}


//运营系统获得可视化系统的token
export function loginByOperateSystem(data) {
  return request({
    url: `/api/auth/loginByOperateSystem?token=${data}`,
    method: 'post',
  })
}


export default { addMenu, editMenu, delMenu, getMenusTree, getChild, treeByMenuId, queryCondition,  
   querySysMenu,queryMenusAndRoleByMenuId,queryById,insertMenu,deleteById,associationMenuAndRole,loginByOperateSystem }
